package clsr.info.blog.common.event;

import com.google.common.collect.Maps;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class EventServiceFactory {
  private Map<Integer, EventService> eventServiceMap = Maps.newHashMap();

  public EventServiceFactory(EventService[] eventService) {
    for (EventService service : eventService) {
      eventServiceMap.put(service.getEventType().getCode(), service);
    }
  }

  public EventService getInstance(EventEnum eventEnum) {
    return eventServiceMap.get(eventEnum.getCode());
  }
}
